package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.FeedTaskQualityDAO;
import cn.edu.scau.cmi.hombio.dao.FodderTypeDAO;
import cn.edu.scau.cmi.hombio.dao.TaskPigstyDAO;

import cn.edu.scau.cmi.hombio.domain.FeedTaskQuality;
import cn.edu.scau.cmi.hombio.domain.FodderType;
import cn.edu.scau.cmi.hombio.domain.TaskPigsty;

import cn.edu.scau.cmi.hombio.service.FeedTaskQualityService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for FeedTaskQuality entities
 * 
 */

@Controller("FeedTaskQualityRestController")

public class FeedTaskQualityRestController {

	/**
	 * DAO injected by Spring that manages FeedTaskQuality entities
	 * 
	 */
	@Autowired
	private FeedTaskQualityDAO feedTaskQualityDAO;

	/**
	 * DAO injected by Spring that manages FodderType entities
	 * 
	 */
	@Autowired
	private FodderTypeDAO fodderTypeDAO;

	/**
	 * DAO injected by Spring that manages TaskPigsty entities
	 * 
	 */
	@Autowired
	private TaskPigstyDAO taskPigstyDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for FeedTaskQuality entities
	 * 
	 */
	@Autowired
	private FeedTaskQualityService feedTaskQualityService;

	/**
	 * Show all FeedTaskQuality entities
	 * 
	 */
	@RequestMapping(value = "/FeedTaskQuality", method = RequestMethod.GET)
	@ResponseBody
	public List<FeedTaskQuality> listFeedTaskQualitys() {
		return new java.util.ArrayList<FeedTaskQuality>(feedTaskQualityService.loadFeedTaskQualitys());
	}

	/**
	* View an existing FodderType entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/fodderType/{foddertype_id}", method = RequestMethod.GET)
	@ResponseBody
	public FodderType loadFeedTaskQualityFodderType(@PathVariable Integer feedtaskquality_id, @PathVariable Integer related_foddertype_id) {
		FodderType foddertype = fodderTypeDAO.findFodderTypeByPrimaryKey(related_foddertype_id, -1, -1);

		return foddertype;
	}

	/**
	* Select an existing FeedTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}", method = RequestMethod.GET)
	@ResponseBody
	public FeedTaskQuality loadFeedTaskQuality(@PathVariable Integer feedtaskquality_id) {
		return feedTaskQualityDAO.findFeedTaskQualityByPrimaryKey(feedtaskquality_id);
	}

	/**
	* Get FodderType entity by FeedTaskQuality
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/fodderType", method = RequestMethod.GET)
	@ResponseBody
	public FodderType getFeedTaskQualityFodderType(@PathVariable Integer feedtaskquality_id) {
		return feedTaskQualityDAO.findFeedTaskQualityByPrimaryKey(feedtaskquality_id).getFodderType();
	}

	/**
	* Delete an existing TaskPigsty entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/taskPigsty/{taskpigsty_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFeedTaskQualityTaskPigsty(@PathVariable Integer feedtaskquality_id, @PathVariable Integer related_taskpigsty_id) {
		feedTaskQualityService.deleteFeedTaskQualityTaskPigsty(feedtaskquality_id, related_taskpigsty_id);
	}

	/**
	* Save an existing FeedTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality", method = RequestMethod.PUT)
	@ResponseBody
	public FeedTaskQuality saveFeedTaskQuality(@RequestBody FeedTaskQuality feedtaskquality) {
		feedTaskQualityService.saveFeedTaskQuality(feedtaskquality);
		return feedTaskQualityDAO.findFeedTaskQualityByPrimaryKey(feedtaskquality.getId());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Delete an existing FeedTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFeedTaskQuality(@PathVariable Integer feedtaskquality_id) {
		FeedTaskQuality feedtaskquality = feedTaskQualityDAO.findFeedTaskQualityByPrimaryKey(feedtaskquality_id);
		feedTaskQualityService.deleteFeedTaskQuality(feedtaskquality);
	}

	/**
	* Create a new TaskPigsty entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/taskPigsty", method = RequestMethod.POST)
	@ResponseBody
	public TaskPigsty newFeedTaskQualityTaskPigsty(@PathVariable Integer feedtaskquality_id, @RequestBody TaskPigsty taskpigsty) {
		feedTaskQualityService.saveFeedTaskQualityTaskPigsty(feedtaskquality_id, taskpigsty);
		return taskPigstyDAO.findTaskPigstyByPrimaryKey(taskpigsty.getId());
	}

	/**
	* Create a new FodderType entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/fodderType", method = RequestMethod.POST)
	@ResponseBody
	public FodderType newFeedTaskQualityFodderType(@PathVariable Integer feedtaskquality_id, @RequestBody FodderType foddertype) {
		feedTaskQualityService.saveFeedTaskQualityFodderType(feedtaskquality_id, foddertype);
		return fodderTypeDAO.findFodderTypeByPrimaryKey(foddertype.getId());
	}

	/**
	* Save an existing FodderType entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/fodderType", method = RequestMethod.PUT)
	@ResponseBody
	public FodderType saveFeedTaskQualityFodderType(@PathVariable Integer feedtaskquality_id, @RequestBody FodderType foddertype) {
		feedTaskQualityService.saveFeedTaskQualityFodderType(feedtaskquality_id, foddertype);
		return fodderTypeDAO.findFodderTypeByPrimaryKey(foddertype.getId());
	}

	/**
	* Get TaskPigsty entity by FeedTaskQuality
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/taskPigsty", method = RequestMethod.GET)
	@ResponseBody
	public TaskPigsty getFeedTaskQualityTaskPigsty(@PathVariable Integer feedtaskquality_id) {
		return feedTaskQualityDAO.findFeedTaskQualityByPrimaryKey(feedtaskquality_id).getTaskPigsty();
	}

	/**
	* Delete an existing FodderType entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/fodderType/{foddertype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteFeedTaskQualityFodderType(@PathVariable Integer feedtaskquality_id, @PathVariable Integer related_foddertype_id) {
		feedTaskQualityService.deleteFeedTaskQualityFodderType(feedtaskquality_id, related_foddertype_id);
	}

	/**
	* Save an existing TaskPigsty entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/taskPigsty", method = RequestMethod.PUT)
	@ResponseBody
	public TaskPigsty saveFeedTaskQualityTaskPigsty(@PathVariable Integer feedtaskquality_id, @RequestBody TaskPigsty taskpigsty) {
		feedTaskQualityService.saveFeedTaskQualityTaskPigsty(feedtaskquality_id, taskpigsty);
		return taskPigstyDAO.findTaskPigstyByPrimaryKey(taskpigsty.getId());
	}

	/**
	* Create a new FeedTaskQuality entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality", method = RequestMethod.POST)
	@ResponseBody
	public FeedTaskQuality newFeedTaskQuality(@RequestBody FeedTaskQuality feedtaskquality) {
		feedTaskQualityService.saveFeedTaskQuality(feedtaskquality);
		return feedTaskQualityDAO.findFeedTaskQualityByPrimaryKey(feedtaskquality.getId());
	}

	/**
	* View an existing TaskPigsty entity
	* 
	*/
	@RequestMapping(value = "/FeedTaskQuality/{feedtaskquality_id}/taskPigsty/{taskpigsty_id}", method = RequestMethod.GET)
	@ResponseBody
	public TaskPigsty loadFeedTaskQualityTaskPigsty(@PathVariable Integer feedtaskquality_id, @PathVariable Integer related_taskpigsty_id) {
		TaskPigsty taskpigsty = taskPigstyDAO.findTaskPigstyByPrimaryKey(related_taskpigsty_id, -1, -1);

		return taskpigsty;
	}
}